
$(function(){
	$('#ss').searchbox({
	    searcher:function(value,name){
			var a = document.createElement("a");
			if(value == null || value == "" || typeof value == "undefined"){
				a.href = /filesharingsystem/;
			}else{
				a.href = "/filesharingsystem/search?keywords="+value;
			}
			a.click();
	    },
		height:'26',
		width:'270',
	    prompt:'Please Input Value'
	});
	
	
	$('#tt').tabs({
		toolPosition:'left',
		border:false,
		width:$(".easyui-layout").width(),
		height:$(".easyui-layout").height(),
		plain:true,
		onSelect:function(){

			//获得当前选中的tab
			var tab = $('#tt').tabs('getSelected');
			//获得当前选中的tab 的href
			var url = $(tab.panel('options')).attr('href');
			tab.panel('refresh', url);
			
		},
	});
	
	 $.get('interface',function(data){
		data.forEach(addTabs);
	 },"json");
	
	$(".nabla").mouseenter(function(){
		$("#info-panel").toggle();
	});
	$(".nabla").mouseout(function(){
		$("#info-panel").hide();
	});
	setCurrentUser();
})

var pageContext_request_contextPath = getRootPath_web();

function addTabs(page){
	$('#tt').tabs('add',{
		title: page,
		border:false,
		selected: false,
		cache:true,
		href: pageContext_request_contextPath+page
	});
}

function getRootPath_web() {
						//获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
	var curWwwPath = window.document.location.href;
						            //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
						            //获取主机地址，如： http://localhost:8083
	var localhostPaht = curWwwPath.substring(0, pos);
	var projectName = pathName.substring(0, pathName.substr(1).indexOf('/')+2);
	return (localhostPaht + projectName);
}

function setCurrentUser(){
	$.get('user',function(data){
		$(".current-user-name").text(data.username);
		$(".level").text(data.role.roleName);

		
		$("#info1").html("用户名:"+data.username);
		$("#info2").html("邮&nbsp;&nbsp;&nbsp;箱:"+data.email);
		$("#info3").html("身&nbsp;&nbsp;&nbsp;份:"+data.role.roleName);
		$("#info4").html("状&nbsp;&nbsp;&nbsp;态:"+(data.state>0?"正常":"禁用"));
		$("#info5").html("注册于:"+data.regDate);
	},"json");	
}
